home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Special 23
/
AMIGAplus Sonderheft 23 (2000)(Falke)(DE)[!].iso
/
Updates
/
Librarys
/
MMULib
/
C_Sources
/
MuSetCacheMode.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-11-28
|
22KB
|
470 lines
/*****************************************************************
** MuSetCacheMode **
** **
** Reprogram MMU tables selectively. **
** Release 40.7, © 1999 THOR-Software inc. **
** 28.11.1999 Thomas Richter **
*****************************************************************/
/// Includes
#include <exec/types.h>
#include <exec/memory.h>
#include <exec/ports.h>
#include <dos/dos.h>
#include <mmu/mmubase.h>
#include <mmu/context.h>
#include <mmu/mmutags.h>
#include <workbench/startup.h>
#include <thor/conversions.h>
#include <proto/exec.h>
#include <proto/mmu.h>
#include <proto/dos.h>
#include <proto/icon.h>
#include <string.h>
///
/// Defines
#define STRINGDATE "28.11.99"
#define STRINGVERSION "40.7"
#define TEMPLATE "ADDRESS=FROM/A,SIZE/A,COPYBACK/S,WRITETHROUGH/S,NOCACHESERIALIZED=CACHEINHIBIT/S,NONSERIAL/S,NOCACHE=IMPRECISE/S,VALID/S,INVALID/S,BLANK/S,IO=IOSPACE/S,NOIO=NOIOSPACE/S,ROM/S,NOROM/S,WRITEPROTECTED/S,NOTWRITEPROTECTED/S,USERONLY/S,SUPERVISORONLY/S,VERBOSE/S"
#define CACHEFLAGS (MAPP_CACHEINHIBIT|MAPP_NONSERIALIZED|MAPP_IMPRECISE|MAPP_COPYBACK)
#define ROMFLAGS (MAPP_ROM|MAPP_WRITEPROTECTED)
#define OPT_ADDRESS 0
#define OPT_SIZE 1
#define OPT_COPYBACK 2
#define OPT_WRITETHROUGH 3
#define OPT_NOCACHE 4
#define OPT_NOCACHESERIALIZED 5
#define OPT_NOCACHEIMPRECISE 6
#define OPT_VALID 7
#define OPT_INVALID 8
#define OPT_BLANK 9
#define OPT_IO 10
#define OPT_NOIO 11
#define OPT_ROM 12
#define OPT_NOROM 13
#define OPT_WRITEPROTECTED 14
#define OPT_NOTWRITEPROTECTED 15
#define OPT_USERONLY 16
#define OPT_SUPERVISORONLY 17
#define OPT_VERBOSE 18
#define OPT_WINDOW 19
#define OPT_COUNT 20
#define WHICH_ALL 3
#define WHICH_USER 1
#define WHICH_SUPER 2
///
/// Statics
struct MMUBase *MMUBase;
struct DosLibrary *DOSBase;
struct ExecBase *SysBase;
struct Library *IconBase;
///
/// Protos
int __asm __saveds main(void);
int SetCacheMode(ULONG from,ULONG size,ULONG flags,ULONG mask,ULONG which);
struct RDArgs *ReadTTArgs(struct WBStartup *msg,LONG args[],struct RDArgs **tmp);
///
char version[]="$VER: MuSetCacheMode " STRINGVERSION " (" STRINGDATE ") © THOR";
/// main
int __asm __saveds main(void)
{
LONG args[OPT_COUNT];
struct RDArgs *rd,*myrd;
struct Process *proc;
int rc=20;
LONG err;
struct WBStartup *msg;
BPTR oldout;
struct MsgPort *oldconsole;
LONG flags,which;
char *whichmsg;
int from=0,size=0;
ULONG mask;
char flagsmsg[256];
SysBase=*((struct ExecBase **)(4L));
memset(args,0,sizeof(LONG)*OPT_COUNT);
flagsmsg[0]='\0'; /* Clear this string */
/* Wait for the workbench startup, if any */
proc=(struct Process *)FindTask(NULL);
if (!(proc->pr_CLI)) {
WaitPort(&(proc->pr_MsgPort));
msg=(struct WBStartup *)GetMsg(&(proc->pr_MsgPort));
} else msg=NULL;
if (DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",37L)) {
if (MMUBase=(struct MMUBase *)OpenLibrary("mmu.library",41L)) {
err=ERROR_REQUIRED_ARG_MISSING;
myrd=NULL; /* reset the temporary ReadArgs */
oldout=NULL;
oldconsole=NULL;
if (msg) {
oldout=SelectOutput(NULL);
oldconsole=SetConsoleTask(NULL);
rd=ReadTTArgs(msg,args,&myrd);
} else rd=ReadArgs(TEMPLATE,args,NULL);
if (rd) {
if (!GetMMUType()) {
Printf("MuSetCacheMode requires a working MMU.\n");
err=10;
} else {
err=0;
if (args[OPT_ADDRESS]==NULL || args[OPT_SIZE]==NULL)
err=ERROR_REQUIRED_ARG_MISSING;
if (err==0) {
if (!StrToL((char *)(args[OPT_ADDRESS]),NULL,&from,16))
err=ERROR_BAD_NUMBER;
if (!StrToL((char *)(args[OPT_SIZE]),NULL,&size,16)) {
err=ERROR_BAD_NUMBER;
} else if (size==0) err=ERROR_BAD_NUMBER;
}
if (err==0) {
flags=0;
mask=0;
if (args[OPT_VALID]) {
mask |= MAPP_INVALID | MAPP_BLANK | MAPP_REPAIRABLE;
strcat(flagsmsg,"valid ");
}
if (args[OPT_IO]) {
flags &= ~CACHEFLAGS;
flags |= MAPP_IO|MAPP_CACHEINHIBIT;
mask |= MAPP_IO|CACHEFLAGS;
strcat(flagsmsg,"IO space ");
}
if (args[OPT_NOIO]) {
mask |= MAPP_IO;
flags &= ~MAPP_IO;
strcat(flagsmsg,"memory space ");
}
if (args[OPT_COPYBACK]) {
flags &= ~CACHEFLAGS;
flags |= MAPP_COPYBACK;
mask |= CACHEFLAGS;
strcat(flagsmsg,"copyback ");
}
if (args[OPT_WRITETHROUGH]) {
flags &= ~CACHEFLAGS; /* writethrough is the default */
mask |= CACHEFLAGS;
strcat(flagsmsg,"writethrough ");
}
if (args[OPT_NOCACHE]) {
flags &= ~CACHEFLAGS;
flags |= MAPP_CACHEINHIBIT;
mask |= CACHEFLAGS;
strcat(flagsmsg,"cacheinhibit ");
}
if (args[OPT_NOCACHESERIALIZED]) {
flags &= ~CACHEFLAGS;
flags |= MAPP_CACHEINHIBIT | MAPP_NONSERIALIZED;
mask |= CACHEFLAGS;
if (!args[OPT_NOCACHEIMPRECISE]) {
strcat(flagsmsg,"cacheinhibit non-serialized ");
}
}
if (args[OPT_NOCACHEIMPRECISE]) {
flags &= ~CACHEFLAGS;